<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="6" :xs="24">
        <el-card class="box-card">
          <template v-slot:header>
            <div class="clearfix">
              <span>个人信息</span>
            </div>
          </template>
          <div>
            <div class="text-center">
              <userAvatar :user="state.user" />
            </div>
            <ul class="list-group list-group-striped">
              <li class="list-group-item">
                <div class="item-label">
                  <svg-icon icon-class="user" />
                  <span>用户名称</span>
                </div>
                <div class="item-value">{{ state.user.userName }}</div>
              </li>
              <li class="list-group-item">
                <div class="item-label">
                  <svg-icon icon-class="phone" />
                  <span>手机号码</span>
                </div>
                <div class="item-value">{{ state.user.phonenumber }}</div>
              </li>
              <li class="list-group-item">
                 <div class="item-label">
                  <svg-icon icon-class="email" />
                  <span>用户邮箱</span>
                </div>
                <div class="item-value">{{ state.user.email }}</div>
              </li>
              <li class="list-group-item">
                <div class="item-label">
                  <svg-icon icon-class="peoples" />
                  <span>所属角色</span>
                </div>
                <div class="item-value">{{ state.roleGroup }}</div>
              </li>
              <li class="list-group-item">
                <div class="item-label">
                  <svg-icon icon-class="date" />
                  <span>注册日期</span>
                </div>
                <div class="item-value">{{ state.user.createTime }}</div>
              </li>
            </ul>
          </div>
        </el-card>
      </el-col>
      <el-col :span="18" :xs="24">
        <el-card class="box-card-right">
          <template v-slot:header>
            <div class="clearfix">
              <span>基本资料</span>
            </div>
          </template>
          <el-tabs v-model="activeTab">
            <el-tab-pane label="基本资料" name="userinfo">
              <userInfo :user="state.user" />
            </el-tab-pane>
            <el-tab-pane label="修改密码" name="resetPwd">
              <resetPwd />
            </el-tab-pane>
          </el-tabs>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup name="Profile">
import userAvatar from "./userAvatar.vue";
import userInfo from "./userInfo.vue";
import resetPwd from "./resetPwd.vue";
import { getUserProfile } from "@/api/system/user";
import useUserStore from "@/store/modules/user";
import { ref, reactive } from "vue";
const activeTab = ref("userinfo");
const state = ref({
  user: {},
  roleGroup: {},
  postGroup: {},
});
const userStore = useUserStore();
function getUser() {
  getUserProfile().then((response) => {
    state.value.user = response.data;
    userStore.avatar = state.value.user.avatar;
    userStore.name = state.value.user.userName;
    userStore.id = state.value.user.userId;
    state.roleGroup = response.roleGroup;
    state.postGroup = response.postGroup;
  });
}

getUser();
// onMounted(() => {
//    console.log(state.value.user);
// }),
</script>
<style scoped>
ul {
  /* background-color: antiquewhite; */
  list-style-type: none;
  border-left: 0;
  border-right: 0;
  border-radius: 0;
  padding-left: 0;
  padding-right: 0;
}

li {
  display: flex;

  /* background-color: aqua; */
  border-bottom: 1px solid #e7eaec;
  border-top: 1px solid #e7eaec;
  margin-bottom: -1px;
  padding: 11px 0px;
  font-size: 13px;
}

.list-group-striped {
  padding: 0;
  list-style-type: none;
}

.list-group-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid #e7eaec;
  font-size: 13px;
}

.item-label {
  display: flex;
  align-items: center;
  gap: 5px;
  color: #666;
  min-width: 100px; /* 固定最小宽度 */
  flex-shrink: 0; /* 防止压缩 */
}

.svg-icon {
  margin-right: 5px;
}
</style>
